import { Entity } from "cesium";
import { getViewer, ViewerNameType, isString } from "yt-cesium";

export const enum ViewerEntityType {
  selectedEntity = "selectedEntity",
  trackedEntity = "trackedEntity",
}

export const setSelectedEntity = generateViewEntity(
  ViewerEntityType.selectedEntity
);

export const setTrackedEntity = generateViewEntity(
  ViewerEntityType.trackedEntity
);

export function generateViewEntity(viewEntityType: ViewerEntityType) {
  return function (entity: Entity, viewerName: ViewerNameType) {
    if (isString(viewerName)) {
      viewerName = getViewer(viewerName);
    }
    viewerName[viewEntityType] = entity;
  };
}

export function onTrackedEntityChange(
  fn: Function,
  viewerName: ViewerNameType
) {
  if (isString(viewerName)) {
    viewerName = getViewer();
  }
}